﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using SpringWaterDataAccess; 
namespace sow
{
	/// <summary>
	/// Summary description for forums.
	/// </summary>
	public partial class forumsmain : System.Web.UI.Page
	{
		private const int DisplayLinks = 5;

		// parameters to add links to the the header and footer
		int TotalTopics = 0;
		int TopicsPerPage = 0;
		string ForumID;
		string ForumName;
		string CategoryID;
		string CategoryName;
		string currPage;
		protected System.Web.UI.WebControls.HyperLink linkHomePage;
		protected System.Web.UI.WebControls.Label lblLevel1;
		protected System.Web.UI.WebControls.DataGrid DataGridForum;
		protected System.Web.UI.WebControls.HyperLink linkCategory;
		protected System.Web.UI.WebControls.Label lblLevel3;
		protected System.Web.UI.WebControls.HyperLink linkForum;
		protected System.Web.UI.WebControls.Label lblLevel2;
		protected System.Web.UI.WebControls.HyperLink linkForums;
		protected System.Web.UI.WebControls.Repeater Repeater1;
        string startTopicID;

	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Retrieve the parameters
			ForumID = Request.QueryString["ForumID"];
			ForumName = Request.QueryString["ForumName"];
			CategoryID = Request.QueryString["CategoryID"];
			CategoryName = Request.QueryString["CategoryName"];
			currPage= Request.QueryString["CurrPage"];
			startTopicID = Request.QueryString["StartID"];

			if (ForumID == null || ForumID == "") 
			{
				ForumID = "11";
            }

			if (CategoryID == null || CategoryID == "") 
			{
				CategoryID = "33";
			}

			HttpCookie emailCookie = Request.Cookies["Email"];

			if (emailCookie != null) 
			{
				 
				if (CategoryID != null && ForumID != null) 
				{
					newArticleButton.Text = "发表新文章";
				} 
			} 
			else  
			{
				 			
				newArticleButton.Text = "请先注册或登录,发表文章";
				//newArticleButton.Attributes.Add("style", "text-decoration:none");
			}

			// populate the navigation pane for forum or category
			ForumDataAccess da = new ForumDataAccess();

			int total;
			DataSet topDS = da.getPosts(0,0,0,0,1,0,out total,"bbs","Top",
				Convert.ToUInt16(CategoryID),"CreateDate");

			DataList1.DataSource = topDS;
			DataList1.DataBind();
		}

		public string getForumSeperator()
		{
			if (ForumName != null) 
				return "->";
			else 
				return "???";

		}

		public string getCategorySeperator()
		{
			if (CategoryName != null) 
				return "->";
			else 
				return "???";

		}
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void newArticleButton_Click(object sender, System.EventArgs e)
		{
			if (Request.Cookies["Email"] == null) 
			{
				Response.Redirect("index.aspx?message=请您先注册/登录，再发表文章 !");
			} 
			else if (CategoryID != null) 
			{
				Response.Redirect("forumPostReply.aspx?categoryID=" +  CategoryID
					+ "&categoryName=" + CategoryName
					+ "&ForumID=" + ForumID
					+ "&ForumName=" + ForumName);
			}
		}
        protected void PostGridView_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
}
}
